﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TimKen.App;
using TimKen.BussLogic;
//using System.Web.Mail;
using System.Net.Mail;
using TimKen.DataEntity;

namespace TimKen.Web.User
{
    public partial class AfterRegister : WebPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (CurrentUserName == null || CurrentUserName == "")
                {
                    Alert("您必须登录！", "../Index.aspx");
                }
                txtTitle.Text = GetLangString("MenuRegisterSuccessfully");
                //txtSubTitle.Text = GetLangString("MenuRegisterSuccessfully");
                txtMessage.Text = GetLangString("Registrationsuccess");
                btnSendEmailCheck.Text = GetLangString("SendConfirmEmail");

                if (Request.QueryString["action"] == "1")
                    this.panelResendEmail.Visible = true;
            }
        }

        protected void btnSendEmailCheck_Click(object sender, EventArgs e)
        {
            WebUserManager manager = new WebUserManager();
            if (Session["tempUserName"] == null)
            {
                Response.Redirect("/Error.aspx");
            }
            try
            {
                string username = Session["tempUserName"].ToString();

                string TimKenUrl = "http://" + Request.ServerVariables["HTTP_HOST"];
                string code = Tools.EncryptUserName(username);
                string path = TimKenUrl + "/User/CheckUser.aspx";
                string checkcode = "<a href=\"" + path + "?code=" + code + "\">" + GetLangString("ClickHere") + "</a>";
                MailMessage mm = new MailMessage();
                MailAddress to = new MailAddress(txtEmail.Text);
                mm.To.Add(to);
                mm.Subject = GetLangString("AuthenticationUserTitle");
                mm.Body = string.Format(GetLangString("AuthenticationUserContent"), checkcode, path, code);
                mm.IsBodyHtml = true;
                Tools.SendEmail(mm);
            }
            catch (CstmException ex)
            {
                Alert(GetLangString("EmailErro"));
                return;
            }
            Alert(GetLangString("EmailSend"));

        }
        //public void SendSMTPEMail(string strSmtpServer, string strFrom, string strFromPass, string strto, string strSubject, string strBody)
        //{
        //    System.Net.Mail.SmtpClient client = new SmtpClient(strSmtpServer);
        //    client.UseDefaultCredentials = false;
        //    client.Credentials = new System.Net.NetworkCredential(strFrom, strFromPass);
        //    client.DeliveryMethod = SmtpDeliveryMethod.Network;
        //    System.Net.Mail.MailMessage message = new MailMessage(strFrom, strto, strSubject, strBody);
        //    message.BodyEncoding = System.Text.Encoding.UTF8;
        //    message.IsBodyHtml = true;
        //    client.Send(message);
        //    //第一个参数如果是163邮箱就写smtp.163.com    
        //    //第二个参数发件人的帐号  
        //    //第三个参数发件人密码   
        //    //第四个参数收件人帐号   
        //    //第五个参数主题    
        //    //第六个参数内容.
        //}
    }
}
